<html>
<head><meta charset="utf-8"><title>Legacy macros can have arbitrary paths · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Legacy.20macros.20can.20have.20arbitrary.20paths.html">Legacy macros can have arbitrary paths</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="198264190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Legacy%20macros%20can%20have%20arbitrary%20paths/near/198264190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Legacy.20macros.20can.20have.20arbitrary.20paths.html#198264190">(May 20 2020 at 22:15)</a>:</h4>
<p>Neat trick that I think rust-analyzer does not currently handle:</p>
<div class="codehilite"><pre><span></span><code><span class="cp">#[macro_export]</span><span class="w"></span>
<span class="n">macro_rules</span><span class="o">!</span><span class="w"> </span><span class="n">mac</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{};</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">pub</span><span class="w"> </span><span class="k">mod</span> <span class="nn">m</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">use</span><span class="w"> </span><span class="n">mac</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>Of course, macros can also be renamed with this.</p>



<a name="198265448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Legacy%20macros%20can%20have%20arbitrary%20paths/near/198265448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Legacy.20macros.20can.20have.20arbitrary.20paths.html#198265448">(May 20 2020 at 22:29)</a>:</h4>
<p>We handle </p>
<div class="codehilite"><pre><span></span><code><span class="n">macro_rules</span><span class="o">!</span><span class="w"> </span><span class="n">_m</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">use</span><span class="w"> </span><span class="n">_m</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">m</span><span class="p">;</span><span class="w"></span>
</code></pre></div>


<p>Not sure about re-export via other module...  it seems like we should do this as well?</p>



<a name="198266832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Legacy%20macros%20can%20have%20arbitrary%20paths/near/198266832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Legacy.20macros.20can.20have.20arbitrary.20paths.html#198266832">(May 20 2020 at 22:45)</a>:</h4>
<p>Ah, I see. <code>ModuleDefId</code> doesn't contain a case for macros though, that seems odd?</p>



<a name="198267078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Legacy%20macros%20can%20have%20arbitrary%20paths/near/198267078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Legacy.20macros.20can.20have.20arbitrary.20paths.html#198267078">(May 20 2020 at 22:48)</a>:</h4>
<p>The idea is that <code>ModuleDefId</code> is for post-expansion things</p>



<a name="198269319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Legacy%20macros%20can%20have%20arbitrary%20paths/near/198269319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Legacy.20macros.20can.20have.20arbitrary.20paths.html#198269319">(May 20 2020 at 23:18)</a>:</h4>
<p>It seems that visibility of macro <em>reexports</em> is not handled correctly (ie. even <code>use</code> adds an entry to the DefMap). This information seems completely missing from <code>ItemScope</code> as well.</p>



<a name="198270950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Legacy%20macros%20can%20have%20arbitrary%20paths/near/198270950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Legacy.20macros.20can.20have.20arbitrary.20paths.html#198270950">(May 20 2020 at 23:42)</a>:</h4>
<p>Ah nevermind, my fault. This is working correctly.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>